package com.material.vtool.task;

import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.material.vtool.entity.BBaseInfoEntity;
import com.material.vtool.entity.BUserInfoEntity;
import com.material.vtool.service.UserInfoService;
import com.material.vtool.service.UserMaterialTypeService;
import com.material.vtool.utils.DateUtil;
import com.material.vtool.wechat.service.WeixinServiceDL;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserAsyncTask {
    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private UserMaterialTypeService userMaterialTypeService;

    /**
     * 异步更新用户信息
     * @param userId 用户ID
     * @param nickName 微信昵称
     */
    @Async
    public void updateUserInfo(Integer userId, String nickName) {
        // 获取微信用户的信息
        BUserInfoEntity bUserInfoEntity = new BUserInfoEntity();
        bUserInfoEntity.setUserId(userId);// 用户ID
        bUserInfoEntity.setUserName(nickName);// 微信昵称
        bUserInfoEntity.setModifyTime(DateUtil.getCurDate());// 修改时间
        bUserInfoEntity.setLastActiveTime(DateUtil.getCurDate());// 最后活跃时间
        userInfoService.modifyWxUserInfo(bUserInfoEntity);
    }

    /**
     * 增加用户的附加信息
     * @param userId 用户ID
     * @param miniCode 小程序标识
     */
    @Async
    public void createUserAttachInfo(Integer userId, String miniCode) {

        // 用户订阅频道
        //userMaterialTypeService.initializeUserMaterialType(userId, miniCode);
    }
}
